#include "nowplayingwidget.h"
#include <QPaintEvent>
#include <QPainter>
#include <QMenu>
#include <QResizeEvent>

NowPlayingWidget::NowPlayingWidget(QWidget *parent)
    : QWidget(parent),
      mode_(SmallSongDetails),
      menu_(new QMenu(this))
{
    QActionGroup* mode_group = new QActionGroup(this);

}

void NowPlayingWidget::DrawContents(QPainter* p)
{
//  switch (mode_) {
//    case SmallSongDetails:
//      if (hypnotoad_) {
//        p->drawPixmap(0, 0, small_ideal_height_, small_ideal_height_,
//                      hypnotoad_->currentPixmap());
//      } else {
//        // Draw the cover
//        p->drawPixmap(0, 0, small_ideal_height_, small_ideal_height_, cover_);
//        if (downloading_covers_) {
//          p->drawPixmap(small_ideal_height_ - 18, 6, 16, 16,
//                        spinner_animation_->currentPixmap());
//        }
//      }

//      // Draw the details
//      p->translate(small_ideal_height_ + kPadding, 0);
//      details_->drawContents(p);
//      p->translate(-small_ideal_height_ - kPadding, 0);
//      break;

//    case LargeSongDetails: {
//      const int total_size =
//          fit_width_ ? width() : qMin(kMaxCoverSize, width());
//      const int x_offset =
//          (width() - cover_loader_options_.desired_height_) / 2;

//      // Draw the black background
//      p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
//                  Qt::black);

//      // Draw the cover
//      if (hypnotoad_) {
//        p->drawPixmap(x_offset, kTopBorder, total_size, total_size,
//                      hypnotoad_->currentPixmap());
//      } else {
//        p->drawPixmap(x_offset, kTopBorder, total_size, total_size, cover_);
//        if (downloading_covers_) {
//          p->drawPixmap(x_offset + 45, 35, 16, 16,
//                        spinner_animation_->currentPixmap());
//        }
//      }

//      // Work out how high the text is going to be
//      const int text_height = details_->size().height();
//      const int gradient_mid = height() - qMax(text_height, kBottomOffset);

//      // Draw the black fade
//      QLinearGradient gradient(0, gradient_mid - kGradientHead, 0,
//                               gradient_mid + kGradientTail);
//      gradient.setColorAt(0, QColor(0, 0, 0, 0));
//      gradient.setColorAt(1, QColor(0, 0, 0, 255));

//      p->fillRect(0, gradient_mid - kGradientHead, width(),
//                  height() - (gradient_mid - kGradientHead), gradient);

//      // Draw the text on top
//      p->translate(x_offset, height() - text_height);
//      details_->drawContents(p);
//      p->translate(-x_offset, -height() + text_height);
//      break;
//    }

//    case LargeNoSongDetails: {
//      const int total_size =
//          fit_width_ ? width() : qMin(kMaxCoverSize, width());
//      const int x_offset =
//          (width() - cover_loader_options_.desired_height_) / 2;

//      // Draw the black background
//      p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
//                  Qt::black);

//      // Draw the cover
//      if (hypnotoad_) {
//        p->drawPixmap(x_offset, kTopBorder, total_size, total_size,
//                      hypnotoad_->currentPixmap());
//      } else {
//        p->drawPixmap(x_offset, kTopBorder, total_size, total_size, cover_);
//        if (downloading_covers_) {
//          p->drawPixmap(x_offset + 45, 35, 16, 16,
//                        spinner_animation_->currentPixmap());
//        }
//      }
//      break;
//    }

//    case LargeSongDetailsBelow:
//      // Work out how high the text is going to be
//      const int text_height = details_->size().height();

//      const int cover_size =
//          fit_width_ ? width() : qMin(kMaxCoverSize, width());
//      const int x_offset =
//          (width() - cover_loader_options_.desired_height_) / 2;

//      if (!fit_width_) {
//        // Draw the black background
//        p->fillRect(QRect(0, kTopBorder, width(), height() - kTopBorder),
//                    Qt::black);
//      }

//      // Draw the cover
//      if (hypnotoad_) {
//        p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size,
//                      hypnotoad_->currentPixmap());
//      } else {
//        p->drawPixmap(x_offset, kTopBorder, cover_size, cover_size, cover_);
//        if (downloading_covers_) {
//          p->drawPixmap(x_offset + 45, 35, 16, 16,
//                        spinner_animation_->currentPixmap());
//        }
//      }

//      // Draw the text below
//      p->translate(x_offset, height() - text_height);
//      details_->drawContents(p);
//      p->translate(-x_offset, -height() + text_height);
//      break;
//  }
}


void NowPlayingWidget::paintEvent(QPaintEvent* e)
{
    QPainter p(this);
    DrawContents(&p);
//    if (!previous_track_.isNull()) {
//      p.setOpacity(previous_track_opacity_);
//      p.drawPixmap(0, 0, previous_track_);
//    }
}

void NowPlayingWidget::resizeEvent(QResizeEvent* e)
{


}
